package com.lgs.demo.base;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * Created by lgs on 2017/3/9.
 * 超级Adapter
 */

public abstract class MySuperBaseAdapter<ITEMBEAN> extends MyBaseAdapter<ITEMBEAN> {

    public MySuperBaseAdapter(ArrayList<ITEMBEAN> datas) {
        super(datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        BaseHolder<ITEMBEAN> holder;
        if (convertView == null) {
            holder = getHolder(parent.getContext());
        } else {
            holder = (BaseHolder<ITEMBEAN>) convertView.getTag();
        }

        ITEMBEAN item = datas.get(position);

        holder.setDataAndRefreshView(item);

        return holder.view;
    }

    /**
     * 条目holder
     *
     * @param context
     * @return
     */
    protected abstract BaseHolder<ITEMBEAN> getHolder(Context context);


}
